/**
 * Created by Administrator on 2015/12/29.
 */
angular.module('ddcx.service',[])
  .service('ddcxService',['$http','$cordovaDatePicker','appItfAopService','$timeout',function($http,$cordovaDatePicker,appItfAopService,$timeout){
    var params={
      "orderTypeParams":{"typeId":"ORDER_ORDER_TYPE"},
      "orderStatusParams":{"typeId":"ORDER_ORDER_STATUS"},
      "gworderStatus":[{"typeId":"01","typeName":"已登记"},{"typeId":"02","typeName":"已经装正式受理"},{"typeId":"03","typeName":"取消"}],
      "gworderStatusName":"",

      //这两个参数主要是因为需要全部的查询，在数据库里不能配置，因为dataId不能为空，所以只能查询出现有的数据然后在添加到上面的两个参数中
      //"orderTypeParamsAll":{"dataId":"","dataName":"所有类型","provinceCode":"71","typeId":"ORDER_ORDER_TYPE","validFlag":"1"},
      //"orderStatusParamsAll":{"dataId":"","dataName":"所有状态","provinceCode":"71","typeId":"ORDER_ORDER_STATUS","validFlag":"1"},
      //"BeginTime":"",
      //"EndTime":"",
      //"OrderType":[{"id":"01","otname":"订单类型一"},{"id":"02","otname":"订单类型二"},{"id":"03","otname":"订单类型三"}],
      //"OrderState":[{"id":"01","osname":"订单状态一"},{"id":"02","osname":"订单状态二"},{"id":"03","osname":"订单状态三"}]
      "OrderType":[],
      "OrderState":[],
      "CustList":{},
      "gworderQueryParams":{
        "preOrderId":"",//预订单编号
        "doOrderStatus":"",//处理状态
        "cityCode":"",//区县编号
        "psptId":"",//身份证号码
        "orderSource":"03",//订单来源非必选
        "rows":"10",
        "page":"0",
        "moreData":true,
        "isRetPageData":"true",
        "createBeginTime":"",//订单创建开始时间
        "createEndTime":"",//订单创建结束时间
      },
      "orderQueryParams":{
        "orderId":"",//订单编码，可选
        "orderType":"",//订单类型，固定传值01：开户，必选;
        "orderSource":"03",//订单来源，01：沃易登；02：移动助销；，必选；以后会固定写03，暂时为了测试数据写01
        "orderStatus":"",//订单状态，可选
        "custName":"",//开户客户姓名，可选
        "serialNumber":"",//开户号码，可选
        "createBeginTime":"",//订单创建开始时间
        "createEndTime":"",//订单创建结束时间
        "departTag":"",//是否查部门下多有订单标记，可选
        "rows":10,//每页返回行数
        "page":0,//第几页
        "moreData":true
      },
      "baikaInfo":"",//返回的白卡信息
      "hasOrder":"1",//判断是否有订单
      "orderData":[],
      "gworderData":[],
      "selectOrder":{},
      "val_kplb":"",
      "feiyong":"",
      "fymx":"",
      "totalfymx":0,
      "ddxk":"",
      "BarSimCard":{},
      "BlueSimCard":{}

    }
    return{
      getParams:function() {
        return params;
      },
      //弹出日历选择框
      showStartDate:function(){

        var options = {
          date: new Date(),
          mode: 'date', // or 'time'
//        minDate: new Date() - 10000,
          allowOldDates: true,
          allowFutureDates: false,
          doneButtonLabel: '确定',
          doneButtonColor: '#F2F3F4',
          cancelButtonLabel: '返回',
          cancelButtonColor: '#000000',
          androidTheme :2
        };

        $cordovaDatePicker.show(options).then(function(date){
          //alert(date);
          //params.orderDate=date;
          //var myDate=new Date();
          params.orderQueryParams.createBeginTime=date.Format('yyyy-MM-dd');
          params.gworderQueryParams.createBeginTime=date.Format('yyyy-MM-dd');
          //alert(params.BeginTime);
//          setDateCondition(date);
//          var myDate=new Date();
//          myDate.setFullYear(date.getFullYear(),date.getMonth(),1);
//          params.BeginTime=myDate.Format('yyyyMMdd');
//
//          myDate=new Date();
//          myDate.setFullYear(date.getFullYear(),date.getMonth(),1);
//          myDate.setMonth(myDate.getMonth() + 1);
//          myDate.setDate(myDate.getDate() - 1);
//          params.EndTime=myDate.Format('yyyyMMdd');

        });

//      var promise = $cordovaDatePicker.show(options);
//
//      return promise;
      },
      showEndDate:function(){

        var options = {
          date: new Date(),
          mode: 'date', // or 'time'
//        minDate: new Date() - 10000,
          allowOldDates: true,
          allowFutureDates: false,
          doneButtonLabel: '确定',
          doneButtonColor: '#F2F3F4',
          cancelButtonLabel: '返回',
          cancelButtonColor: '#000000',
          androidTheme :2
        };

        $cordovaDatePicker.show(options).then(function(date){
          params.orderQueryParams.createEndTime=date.Format('yyyy-MM-dd');
          params.gworderQueryParams.createEndTime=date.Format('yyyy-MM-dd');
        });
      },

      //订单类型查询
      queryOrderType:function(){
        return appItfAopService.do_queryStaticList_req(params.orderTypeParams);
      },
      //订单状态查询
      queryOrderStatus:function()
      {
        return appItfAopService.do_queryStaticList_req(params.orderStatusParams);
      },
      //下拉刷新
      doRefresh:function(params)
      {
        return appItfAopService.do_queryOrderList_req(params)
      },
      doGwRefresh:function(params)
      {
        return appItfAopService.do_queryFixNetOrderList_req(params)
      },
      getorderQueryParams:function(param){
        params.orderQueryParams=param;
      },
       //上拉加载
      doLoadMore:function(params)
      {
        //console.log('上拉加载');
        return appItfAopService.do_queryOrderList_req(params);
//        params.PageNum++;
//        console.log(params);
//        return AppItfService.do_Z40001_req(params).then(function(data){
////        alert(data.Response.orderList.order);
////        alert(params.orderData);
//          if(data.Response.orderList.order.length==0) {
//            params.moreData=false;
//          } else {
//            params.moreData=true;
//          }
//          params.orderData = params.orderData.concat(data.Response.orderList.order);
////        alert(params.orderData);
//        },function(error){
//          console.log("订单查询-上拉加载失败")
//        });
      },
      ReadIccid:function(param,success,error){
        bluetooth.sr_iccid(param,success,error);
      },
      writeIMSI:function(param,success,error){
          bluetooth.sr_imsi(param,success,error);
      },
      SimcardInfo2G:function(param){
       return appItfAopService.do_SimcardInfo2G_req(param);
      },
      SimcardInfo4G:function(param){
        return appItfAopService.do_WhiteSimInfo4G_req(param);
      },
      transmitCardOk2G:function(param){
        return appItfAopService.do_transmitCardOk2G_req(param);
    },
      transmitCardOk4G:function(param){
        return appItfAopService.do_transmitCardOkThenToB4G_req(param);
      },
      doCardInfoSync4G:function(param){
      return appItfAopService.do_cardInfoSync4G_req(param);
      },
      docreateUserSubmit2G:function(param){
        return appItfAopService.do_createUserSubmit2G_req(param)
      },
      docreateUserSubmit4G:function(param){
        return appItfAopService.do_createUserSubmit4G_req(param);
      },
      finishOrder4G:function(param){
        return appItfAopService.do_finishOrder4G_req(param);
      },
      //插入日志
      insertLog:function(param)
      {
        return appItfAopService.do_insertLog_req(param);
      }
    }
  }]);
